package com.njwb.day15.zqzb.sql;

import java.util.Scanner;

public class Main {
    private static Scanner scanner=new Scanner(System.in);
    public static void main(String[] args) {
        while (true){
            System.out.println("1.添加\n" +
                    "2.删除\n" +
                    "3.修改\n" +
                    "4.查询\n" +
                    "5.查询全部\n" +
                    "6.退出");
            System.out.println("请输入操作：");
            int a=scanner.nextInt();
            switch (a){
                case 1:
                    add();break;
                case 2:
                    delete();break;
                case 3:
                    update();break;
                case 4:
                    select();break;
                case 5:
                    show();break;
                case 6:
                    System.exit(0);
                    break;
                default:
                    System.out.println("无效的操作!!!");
            }
        }

    }

    private static void add() {
        System.out.println("请输入学号：");
        int no = scanner.nextInt();
        if (!Util.select(no)) { // 已存在
            System.out.println("学号已存在！！！");
            return;
        }
        System.out.println("请输入姓名：");
        String name = scanner.next();
        System.out.println("请输入国家：");
        String from = scanner.next();
        Util.addMember(no, name, from);
    }

    private static void delete() {
        System.out.println("请输入学号：");
        int no = scanner.nextInt();
        if (Util.select(no)) { // 不存在
            System.out.println("该学号不存在！！！");
            return;
        }
        Util.deleteMember(no);
    }

    private static void update() {
        System.out.println("请输入学号：");
        int no = scanner.nextInt();
        if (Util.select(no)) { // 不存在
            System.out.println("该学号不存在！！！");
            return;
        }
        System.out.println("请输入姓名：");
        String name = scanner.next();
        System.out.println("请输入国家：");
        String from = scanner.next();
        Util.updateMemberPhone(no, name, from);
    }

    private static void select() {
        System.out.println("请输入学号：");
        int no = scanner.nextInt();
        if (Util.select(no)) {
            System.out.println("该学号不存在！");
        }
    }

    private static void show() {
        Util.queryMembers();
    }
}
